<template>
  <div>
    <div class="top">
      <el-form ref="form" :model="form" :rules="rules">
        <el-descriptions :colon="false">
          <el-descriptions-item label="员工帐号:">
            <el-form-item prop="account">
              <el-input v-model="form.employeeNumber" placeholder="请输入员工帐号" />
            </el-form-item>
          </el-descriptions-item>
          <el-descriptions-item label="员工姓名:">
            <el-form-item prop="name">
              <el-input v-model="form.name" placeholder="请输入员工姓名" />
            </el-form-item>
          </el-descriptions-item>
          <el-descriptions-item label="工作模式:">
            <el-form-item prop="phone">
              <el-select v-model="form.workPatternName" placeholder="请选择">
                <!-- <el-option
                  :label="1"
                  :value="1"
                /> -->
              </el-select>
            </el-form-item>
          </el-descriptions-item>
          <el-descriptions-item label="月份:" label-class-name="organ">
            <el-form-item prop="month">
              <el-date-picker
                v-model="form.month"
                type="month"
                placeholder="选择月"
              />
            </el-form-item>
          </el-descriptions-item>
          <el-descriptions-item label="所属机构:">
            <el-form-item prop="agentId">

              <el-select
                v-model="form.agentId"
                style="width: 100%"
                clearable
                placeholder="请选择父级权限"
              >
                <el-tree
                  node-key="id"
                  :data="treeData"
                  class="add_tree"
                  :props="defaultProps"
                  :expand-on-click-node="false"
                  :check-on-click-node="true"
                >
                  <span slot-scope="{ data }" class="custom-tree-node">
                    <el-option
                      style="padding: 0"
                      :label="data.name"
                      :value="data.id"
                    />
                  </span>
                </el-tree>
              </el-select>

            </el-form-item>
          </el-descriptions-item>
          <el-descriptions-item label-class-name="btnGroup">
            <el-button type="primary" @click="btnSearch">搜索</el-button>
            <el-button @click="btnReset">重置</el-button>
          </el-descriptions-item>
        </el-descriptions>
      </el-form>
    </div>

    <div class="bottom">
      <el-table :data="tableData.items" stripe style="width: 100%">
        <el-table-column fixed="left" type="index" label="序号" width="50px" />
        <el-table-column fixed="left" label="员工帐号" prop="employeeNumber" width="150px" />
        <el-table-column fixed="left" width="150px" prop="name" label="员工姓名" />
        <el-table-column fixed="left" width="150px" label="员工电话" prop="phone" />
        <el-table-column fixed="left" width="150px" label="员工角色" prop="userType" />
        <el-table-column fixed="left" width="150px" label="当前工作模式" prop="workPatternName" />
        <el-table-column width="50px" label="操作" />
      </el-table>

      <div class="pagination">
        <el-pagination
          :current-page="pageParams.page"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="pageParams.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="Number(tableData.counts)"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { organTree, getGrade } from '@/api/website'

export default {
  data() {
    return {
      // 查询表单数据
      form: {
        employeeNumber: '',
        agentId: -1 && '',
        name: '',
        phone: '',
        month: '',
        workPatternName: ''
      },
      // 表单校验
      rules: {
        account: [],
        agentId: [],
        name: [],
        phone: []
      },
      // 快递员查找表单
      tableData: {},
      // 获取分页数据参数
      pageParams: {
        page: 1,
        pageSize: 10
      },
      treeData: [], // 树形控件数据
      defaultProps: {
        label: 'name',
        children: 'children'
      },
      label: '',
      selectOption: ''
    }
  },

  created() {
    this.getMessage()
    this.getSelect()
  },

  methods: {
    // 获取数据
    async getMessage() {
      const result = await getGrade(this.pageParams)
      this.tableData = result.data.data
    },

    // 分页器
    handleSizeChange(pageSize) {
      this.pageParams.pageSize = pageSize
      this.getMessage(this.pageParams)
    },
    handleCurrentChange(currentPage) {
      this.pageParams.page = currentPage
      this.getMessage(this.pageParams)
    },

    // 获取树状机构信息
    async getSelect() {
      const result = await organTree()
      this.treeData = JSON.parse(result.data.data)
    },

    // 点击重置
    btnReset() {
      this.$refs.form.resetFields()
      this.pageParams = {
        page: 1,
        pageSize: 10
      }
      this.getMessage()
    },

    // 点击搜索
    btnSearch() {
      this.pageParams = { ...this.pageParams, ...this.form }
      this.getMessage()
    }
  }
}
</script>

<style scoped>
.top,
.bottom
{
  margin: 20px;
  padding: 30px;
  background-color: #fff;
}

.top ::v-deep .el-input {
  width: 380px;
  height: 40px;
}

.top ::v-deep .el-descriptions-item__container {
  line-height: 40px;
}

.top ::v-deep .organ {
  padding-left: 28px;
}

.top ::v-deep .btnGroup {
  margin-right: 0;
}

.top ::v-deep .el-descriptions-item__container {
  height: 45px;
}

.pagination {
  text-align: center;
  margin-top: 20px;
}

a {
    color: deepskyblue;
}
</style>
